package com.deyou.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.deyou.R;
import com.deyou.base.BaseActivity;
import com.deyou.event.DebookRulesEvent;
import com.deyou.event.HouseInfoEvent;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CommonInputActivity extends BaseActivity {

    @BindView(R.id.iv_left_back)
    ImageView ivLeftBack;
    @BindView(R.id.tv_mid_title)
    TextView tvMidTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.edt_custom_debook_rule)
    EditText edtCustomDebookRule;

    private int showType = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_debook_rules);
        ButterKnife.bind(this);
        initData();
        initView();
    }

    private void initData() {
        showType = getIntent().getExtras().getInt("showType");
    }

    private void initView() {
        if (1 == showType) {
            tvMidTitle.setText("房源标题");
            edtCustomDebookRule.setHint("请输入您的房源标题");
        } else if (2 == showType) {
            tvMidTitle.setText("房源描述");
            edtCustomDebookRule.setHint("请输入您的房源描述");
        } else if (3 == showType) {
            tvMidTitle.setText("房源守则");
            edtCustomDebookRule.setHint("请输入您的房源守则");
        }
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText("保存");
        tvRight.setTextColor(getResources().getColor(R.color.color_FF832D));
    }

    @OnClick({R.id.iv_left_back, R.id.tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_left_back:
                finish();
                break;
            case R.id.tv_right:
                if (TextUtils.isEmpty(edtCustomDebookRule.getText().toString())) {
                    showToast("请输入内容");
                    return;
                }
                HouseInfoEvent event = new HouseInfoEvent(showType, edtCustomDebookRule.getText().toString());
                EventBus.getDefault().post(event);
                finish();
                break;
        }
    }
}
